package com.example.food03.bool;

import static com.example.food03.MainActivity3.h2;
import static com.example.food03.MainActivity3.h2_2;

import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;

import com.example.food03.LoginActivity;
import com.example.food03.MainActivity;
import com.example.food03.MainActivity3;
import com.example.food03.R;
import com.example.food03.strongweb_bool.HTMLtool;

import java.sql.Struct;
import java.util.List;

public class WxServiceAdapter_3_3 extends BaseAdapter {
    private Context context;
    private List<WxService2> list;
    public static int o=0;
    String pp="";
    public WxServiceAdapter_3_3(Context c, List<WxService2> list){
      this.context=c;
        this.list=list;
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object getItem(int i) {
        return list.get(i);
    }
    @Override
    public long getItemId(int i) {
        return i;
    }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        View view1;
        if(view!=null){
            view1=view;
        }else {
            view1=View.inflate(context, R.layout.lu_3_3,null);
        }
        ImageView imageView=view1.findViewById(R.id.imageView);
        imageView.setImageBitmap(list.get(i).getImgd());
        TextView t1=view1.findViewById(R.id.textView);
        TextView t2=view1.findViewById(R.id.textView99);
        WxService2 wxService=list.get(i);
        t1.setText(wxService.getString());
        t2.setText("单价："+wxService.getdouble()+"元");
        Button b1=view1.findViewById(R.id.button3_1);
        RadioButton g1=view1.findViewById(R.id.insert3_3_1);
        Log.d("你好呀",i+"");
        //查看评论的按钮
        b1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                o=i;
                AlertDialog.Builder customizeDialog =
                        new AlertDialog.Builder(context);
                final View dialogView = LayoutInflater.from(context)
                        .inflate(R.layout.diaolog3_1,null);
                customizeDialog.setTitle("  评论  ");
                customizeDialog.setView(dialogView);
                ListView mList=dialogView.findViewById(R.id.lv3_1);
                ListAdapter3_1 listAdapter=new ListAdapter3_1();//listview的一个适配器
                SimpleAdapter spcAdapter = new SimpleAdapter(context,listAdapter.getData(),R.layout.diaolog3_1_listview,
                        new String[]{"title","ii","img"}, new int[]{R.id.textView7,R.id.textView8,R.id.imageView2});//放适配器工具
                mList.setAdapter(spcAdapter);
                Log.d("kkk4", MainActivity3.order3_1[0]);
                customizeDialog.setPositiveButton("确定",
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                // 获取EditView中的输入内容
                                /*EditText edit_text =
                                        (EditText) dialogView.findViewById(R.id.edit_text);
                                Toast.makeText(context,
                                        edit_text.getText().toString(),
                                        Toast.LENGTH_SHORT).show();*/
                               // Log.d("kkk4", MainActivity3.comment3_1[1]+"");

                            }
                        });
                customizeDialog.show();
            }
        });
        //测
        if(LoginActivity.pwd2!=0){
            if(h2_2[i].equals("1")){
                g1.setChecked(true);
                //Log.d("qqq2",h2_2[i]+"iii");
            }
           // g1.setChecked(true);
            //Log.d("qqq2",h2_2[i]);
        }
        pp=g1.isChecked()+"";
        //添加收藏的按钮
        g1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(LoginActivity.pwd2!=0){
                    new Thread(new Runnable() {
                        @Override
                        public void run() {
                            try {
                                String h1= HTMLtool.getHtml("http://192.168.43.126:8080/foodService/userCollectFood.do?user_id="+
                                        LoginActivity.pwd2+"&&food_id="
                                        +MainActivity.shop_foodid[MainActivity.ii][i]);
                                Log.d("ooo",LoginActivity.pwd2+"");
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
                    }).start();
                    if(pp.equals("true"))
                        g1.setChecked(false);
                    pp = g1.isChecked() + "";
                    //Toast.makeText(context,"已收藏!"+ MainActivity.shop_foodid[0][i],Toast.LENGTH_LONG).show();
                }else {
                    if(g1.isChecked()){
                        g1.setChecked(false);
                    }else{
                        g1.setChecked(true);
                    }
                    Toast.makeText(context,"还未登录！",Toast.LENGTH_LONG).show();
                }
            }
        });
        imageView.getImageAlpha();
        return view1;
    }
}
